<template>
  <div class="app-container">
    <h1 style="text-align: center">会员信息管理</h1>
    <el-row style="margin-top: 50px">
      <el-col :span="12" :offset="5">
        <el-form label-position="right" label-width="80px" :model="form">
          <el-form-item label="用户名">
            <el-input v-model="form.username"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.password" type="password"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-select v-model="form.sex" placeholder="请选择" style="width: 100%">
              <el-option label="男" value="男">
              </el-option>
              <el-option label="女" value="女">
              </el-option>
            </el-select>

          </el-form-item>

          <el-form-item label="年龄">
            <el-input v-model="form.age" type="number"></el-input>
          </el-form-item>

          <el-form-item label="电话">
            <el-input v-model="form.phone" type="number"></el-input>
          </el-form-item>
          <el-form-item style="margin-top: 45px">
            <el-col :span="8" :offset="8">
              <el-button :loading="loading" type="primary" style="width:100%"
                         @click="userUpdate">确定
              </el-button>
            </el-col>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "index",
  data() {
    return {
      form: {},
      loading: false
    }
  },
  created() {
    const user = JSON.parse(sessionStorage.getItem('user'))
    this.form = {...user}
  },
  methods: {
    userUpdate() {
      request({
        url: '/user',
        method: 'POST',
        data: this.form
      }).then(v => {
        sessionStorage.setItem('user', JSON.stringify(v.data))
        this.$message({
          message: '用户信息更新成功！',
          type: 'success'
        });
      })
    }
  }
}
</script>

<style scoped>

</style>
